﻿# import sys;
import img2;
from tqdm import tqdm
import yuque;
import json;
# import re;
# import numpy as np;
# import requests as req
# from PIL import Image, ImageDraw, ImageFont
# from io import BytesIO;
# import toke;
import time;
import dirFile



if __name__=="__main__":

	img=img2.img();

	# openId='oW2Wk1TaSG1GpDniqN7bACDJCOKk'

	# img.createImgLt(openId,'18801263882')

	dr=dirFile.dirFileInfo()

	yq=yuque.yueque()

	second = yq.sleeptime(0,0,20);

	while 1==1:

		time.sleep(second)

		endTime=time.strftime("%Y-%m-%d %H:%M:%S");

		strTime=json.loads(open('date.json','r+').read())['strTime'];

		res=img.getDb("SELECT a.mobile,a.open_id FROM weizandata.`wxgongzhonghaophone` a WHERE a.`open_id` IS NOT NULL AND a.`last_event_time`BETWEEN '"+strTime+"' AND '"+endTime+"';")

		print('res==>',res)

		if len(res)>0:

			for i in tqdm(range(len(res))):

				mobile=res[i][0]

				open_id=res[i][1]

				try:	

					print(mobile)

					img.createImgLt(open_id,mobile)

				except:

					print('erro')


			fs=open('date.json','w+')

			fs.write(json.dumps({'strTime':endTime}))

			fs.close()
	
			#获取1k的文件重新写入

		mobileList=dr.getyiK()

		mobileListStr='(\''+'\',\''.join(mobileList)+'\')'

		res=img.getDb("SELECT a.mobile,a.open_id FROM weizandata.`wxgongzhonghaophone` a WHERE a.`mobile` in "+mobileListStr+";")

		print('res==>',res)

		if len(res)>0:

			for i in tqdm(range(len(res))):

				mobile=res[i][0]

				open_id=res[i][1]

				try:	

					print(mobile)

					img.createImgLt(open_id,mobile)

				except:

					print('erro')